package com.iwhalecloud.bss.kite.cucc.web.service.accept.handler.module;

import com.iwhalecloud.bss.kite.client.dto.inst.InstAttrDTO;
import com.iwhalecloud.bss.kite.client.vo.scene.CommonAttrVO;
import com.iwhalecloud.bss.kite.client.vo.scene.ModuleVO;
import com.iwhalecloud.bss.kite.cucc.client.api.attr.ILocalQueryScenePersonInfoService;
import com.iwhalecloud.bss.kite.cucc.client.vo.scene.ConnectionPersonInfoVO;
import com.iwhalecloud.bss.kite.cucc.client.vo.scene.SceneNewOfferSeneVO;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalKeyConsts;
import com.iwhalecloud.bss.kite.cucc.common.util.AssemblyAttrDtoUtils;
import com.iwhalecloud.bss.kite.web.service.accept.bo.AcceptContext;
import com.iwhalecloud.bss.kite.web.service.accept.bo.SceneModule;
import com.iwhalecloud.bss.kite.web.service.accept.handler.module.AbstractModuleHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <Description> 联系人 <br>
 *
 * @author <br>
 *
 */
@Service
public class ConnectionPersonInfoModuleHandler extends AbstractModuleHandler {


    @Autowired
    private ILocalQueryScenePersonInfoService queryScenePersonService;


    @Override
    public List<ModuleVO> execute(AcceptContext context, SceneModule sceneModule) {

        List<InstAttrDTO> attrConfigs = queryScenePersonService.listContractInfoAttrs(context.getAcceptRequest().getSceneInstId())
            .getResultObject().stream().filter(instAttrDTO -> LocalKeyConsts.KITE_ATTR_CONFIG_SHOW_TYPE_D.equals(instAttrDTO.getShowType())).collect(Collectors.toList());
        List<CommonAttrVO> commonAttrList =  AssemblyAttrDtoUtils.assemblyVO(attrConfigs);

        ConnectionPersonInfoVO connectionPersonInfoVO = new ConnectionPersonInfoVO();
        connectionPersonInfoVO.setConnectionPersonAttr(commonAttrList);

        SceneNewOfferSeneVO sceneAccountInfoVo = (SceneNewOfferSeneVO) context.getSceneVo();
        sceneAccountInfoVo.setConnectionPersonInfo(connectionPersonInfoVO);

        return Collections.singletonList(connectionPersonInfoVO);
    }


    @Override
    public List<ModuleVO> previewSceneVo(AcceptContext context, SceneModule sceneModule) {
        List<InstAttrDTO> attrConfigs = queryScenePersonService.listContractInfoAttrs(context.getAcceptRequest().getSceneInstId())
            .getResultObject();

        ConnectionPersonInfoVO connectionPersonInfoVO = new ConnectionPersonInfoVO();
        connectionPersonInfoVO.setConnectionPersonAttr(AssemblyAttrDtoUtils.assemblyCommonVO(attrConfigs));

        SceneNewOfferSeneVO sceneAccountInfoVo = (SceneNewOfferSeneVO) context.getSceneVo();
        sceneAccountInfoVo.setConnectionPersonInfo(connectionPersonInfoVO);

        return Collections.singletonList(connectionPersonInfoVO);
    }

}
